package com.csd.action.security;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.csd.helper.IConstant;
import com.csd.pojo.Project;
import com.csd.service.IManagerService;
import com.csd.service.ITeacherService;
import com.csd.service.ITeamService;
import com.csd.serviceImpl.ProjectService;
import com.csd.vo.UserVO;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * Action:登陆
 * 
 * @author csd
 * @version 1.0
 * 
 * <br>
 *          修订时间：2009-12-17 <br>
 *          修改原因：创建文件 <br>
 *          修改人：何文深 <br>
 * 
 */
public class LoginAction  {
	
	/**把接受的数据包装成对象*/
	private UserVO userVO;
	
	private ITeamService teamService;
	
	private ITeacherService teacherService;
	
	private IManagerService managerService;
	
	public UserVO getUserVO() {
		return userVO;
	}

	public void setUserVO(UserVO userVO) {
		this.userVO = userVO;
	}

	public ITeamService getTeamService() {
		return teamService;
	}

	public void setTeamService(ITeamService teamService) {
		this.teamService = teamService;
	}

	public ITeacherService getTeacherService() {
		return teacherService;
	}

	public void setTeacherService(ITeacherService teacherService) {
		this.teacherService = teacherService;
	}

	public IManagerService getManagerService() {
		return managerService;
	}

	public void setManagerService(IManagerService managerService) {
		this.managerService = managerService;
	}

	public String execute() throws Exception {
		
		String text = "fail";
		int type = Integer.parseInt(userVO.getType());
	
		//查看登录类型，调用不同的业务逻辑方法
		switch (type) {
		case 1:
			userVO = managerService.login(userVO);
			if (userVO != null) {

				text = "manager"; // 跳动管理员页面
			}
			break;
		case 2:
			userVO = teacherService.login(userVO);
			if (userVO != null) {
				text = "teacher"; // 跳动教师页面
			}
			break;
		case 3:
			userVO = teamService.login(userVO);
			if (userVO != null) {
				text = "team"; // 跳动团队页面
			}
			break;
		
		default:
			break;
		}

		HttpSession httpSession = ServletActionContext.getRequest().getSession();
		//不是游客，则保存用户的登录信息
		if (userVO!=null && !userVO.getType().equals(IConstant.otherRole)) {
			httpSession.setAttribute(IConstant.userVO, userVO);	
		}
		else
		{ 
			text = "others"; // 跳动游客页面
		}
		return text;
	}
}
